<?php
class UserModel extends BaseModel
{
    /**
     * 获取用户基本信息
     * @param int $uid
     * @author ice <iceinto@mallog.com.cn>
     */
    public function getOne($uid)
    {
        return $this->getById($uid, 'id,num');
    }

    /**
     * 获取用户列表
     * @param array $map 查询条件
     * @param string $limit 分页条件
     * @param string $order 排序
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getList($map = null, $limit = null, $order = null)
    {
        $fields = 'id,num,email';
        return $this->getListByWhere($map, $fields, $limit, $order);
    }

    /**
     * Access to current user id number
     * @param int $uid user id
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getNum($uid)
    {
        $user = $this->getById($uid, 'num');
        if ($user) {
            return $user['num'];
        } else {
            return null;
        }
    }

    /**
     * 获取美工等级
     * @param int $uid
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getMLevel($uid)
    {
        $map = array();
        $map['m_role_user.user_id'] = $uid;
        $map['m_role_user.role_id'] = 3;
        return $this->field('m_user.level')
            ->join('INNER JOIN m_role_user ON m_user.id = m_role_user.user_id')
            ->where($map)
            ->find();
    }
    
    /**
     * 获取美工人员列表
     * @author Ice <iceinto@mallog.com.cn> 
     */
    public function getDesList(){
    	$map = array();
    	$map['m_role_user.role_id'] = 3;
    	return $this->field('m_user.id,m_user.num')
    	->join('INNER JOIN m_role_user ON m_user.id = m_role_user.user_id')
    	->where($map)
    	->select();
    }
}